package com.zpark.frog;

import java.util.Comparator;

/**
 * 水稻类：实现了比较器，编写了比较逻辑
 *      如果横坐标相同，则比较纵坐标
 * 属性：x->横坐标，y->纵坐标
 */

public class Plant implements Comparator<Plant> {
    // 水稻的x坐标
    private int x;
    // 水稻的y坐标
    private int y;

    public Plant() {

    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public Plant(int x, int y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public String toString() {
        return "Plant{" +
                "x=" + x +
                ", y=" + y +
                '}';
    }

    @Override
    public int compare(Plant p1, Plant p2) {
        if (p1.getX() == p2.getY())
            return p1.getY() - p2.getY();
            return p1.getX() - p2.getX();
    }

}
